package kr.hyunist.androidcomplete01saeildamil.ch16;

import java.util.*;

import kr.hyunist.androidcomplete01saeildamil.*;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;

public class AlertDialogTest extends Activity {
	final static int SampleDialog = 0;
	final static int QuestionDialog = 1;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.alertdialogtest);

		Button btn1 = (Button) findViewById(R.id.alertdialogtestbtn1);
		btn1.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showDialog(SampleDialog);
			}

		});

		Button btn2 = (Button) findViewById(R.id.alertdialogtestbtn2);
		btn2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				showDialog(QuestionDialog);
			}

		});
	}

	@Override
	protected Dialog onCreateDialog(int id, Bundle args) {
		switch (id) {
		case SampleDialog:
			return new AlertDialog.Builder(AlertDialogTest.this)
					.setTitle("알립니다").setIcon(R.drawable.ic_launcher)
					.setMessage("알립니다!").setPositiveButton("확인", null).create();

		case QuestionDialog:
			return new AlertDialog.Builder(AlertDialogTest.this).setTitle("질문")
					.setMessage("점심 뭐잡솻어?").setPositiveButton("짬뽕", null)
					.setNegativeButton("굶었음", null).create();

		}

		return null;
	}

	@Override
	protected void onPrepareDialog(int id, Dialog dialog) {
		switch(id){
		case SampleDialog:
			break;
			
		case QuestionDialog:
			Calendar cal = Calendar.getInstance();
			String stime = String.format("%d시 %d분 %d초", cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
			dialog.setTitle(stime);
			break;
		}
	}

}
